package org.apache.solr.ocean.search;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public class Distance {
  private double latitude;
  private double longitude;
  private double distanceMiles;
  private int hashCode;

  public Distance(double latitude, double longitude, double distanceMiles) {
    this.latitude = latitude;
    this.longitude = longitude;
    this.distanceMiles = distanceMiles;
    HashCodeBuilder builder = new HashCodeBuilder(679, 121);
    builder.append(latitude);
    builder.append(longitude);
    builder.append(distanceMiles);
    hashCode = builder.toHashCode();
  }

  public boolean equals(Object object) {
    if (!(object instanceof Distance))
      return false;
    if (object == null)
      return false;
    Distance other = (Distance) object;
    EqualsBuilder equalsBuilder = new EqualsBuilder();
    equalsBuilder.append(latitude, other.latitude);
    equalsBuilder.append(longitude, other.longitude);
    equalsBuilder.append(distanceMiles, other.distanceMiles);
    return equalsBuilder.isEquals();
  }

  public int hashCode() {
    return hashCode;
  }

  public double getLatitude() {
    return latitude;
  }

  public double getLongitude() {
    return longitude;
  }

  public double getDistanceMiles() {
    return distanceMiles;
  }
}